/* Author: David McCoy dave.mccoy@cospandesign.com
 *
 *     This file is part of DLCM\SubServ.
 *
 *  DLCM\SubServ is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  DLCM\SubServ is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with DLCM\SubServ.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * CheckBoxWidget.java
 *
 * Created on Mar 31, 2010, 4:03:31 PM
 */

package com.cospandesign.gui.pubsub.widgets;

import pubsub.PubSubManager;
import dlcm.Member;
import dlcm.Structure;


public class CheckBoxWidget extends javax.swing.JFrame implements Widget{

    String ChannelName;
    String MemberName;
    dlcm.Structure mStructure;
    dlcm.Member mMember;
    PubSubManager Parent;

    /** Creates new form ButtonWidget */
    public CheckBoxWidget() {
        initComponents();
    }

    // <editor-fold defaultstate="collapsed" desc="Static Functions">
    public static String GetWidgetName() {
        return "CheckBox Widget";
    }
// </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Inherited Widget Functions">
    public void ReceiveMessage(Structure structure) {
        CheckBox.setSelected((Boolean)structure.getMember(MemberName).Data);
    }

    public boolean CanUseMember(Member member) {
        if (member.Data.getClass().equals(Boolean.class)){
            return true;
        }
        return false;
    }

    public void SetupWidget(String channelName, String memberName, Structure structure, PubSubManager parent) {
        ChannelName = channelName;
        MemberName = memberName;
        mStructure = structure;
        mMember = mStructure.getMember(memberName);
        Parent = parent;
        setTitle(memberName + " Text Box");
        setVisible(true);
    }

    public void setWidgetVisibility(boolean visible) {
        setVisible(visible);
    }
// </editor-fold>
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        CheckBox = new javax.swing.JCheckBox();

        setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/cospandesign/resources/cospandesign.png")));

        CheckBox.setText("Boolean");
        CheckBox.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        CheckBox.setName("CheckBox"); // NOI18N
        CheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CheckBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(124, Short.MAX_VALUE)
                .addComponent(CheckBox)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(CheckBox)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CheckBoxActionPerformed
        mStructure.getMember(MemberName).Data = CheckBox.isSelected();
        Parent.PublishStructure(ChannelName, mStructure);
    }//GEN-LAST:event_CheckBoxActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox CheckBox;
    // End of variables declaration//GEN-END:variables



}
